//
//  TransactionRecordCell.swift
//  SCA
//
//  Created by tjun on 2025/9/6.
//

import UIKit

struct TransactionRecordModel {
    let Id: Int
    let type: String
    let typeDisp: String
    let amount: String
    let amountDisp: String
    let date: String
    let op: String
}

class TransactionRecordCell: BaseTableViewCell {
    
    var model: TransactionRecordModel! {
        didSet {
            if model.op == "-" {
                accountLabel.textColor = UIColorMake(0xFC060A)
            } else {
                accountLabel.textColor = UIColorMake(0x07982B)
            }
            
            typeLabel.text = model.typeDisp
            dateLabel.text = model.date
            accountLabel.text = model.op + model.amountDisp
        }
    }
    
    var indexPath: IndexPath? {
        didSet {
            guard let indexPath = indexPath else { return }
            if indexPath.row % 2 == 0 {
                containerView.backgroundColor = .clear
            } else {
                containerView.backgroundColor = UIColorMake(0x2E3036)
            }
        }
    }

    private let containerView = UIView()
    private let typeLabel = UILabel(font: UIFontMediumMake(12), textColor: UIColor.white)
    private let accountLabel = UILabel(font: UIFontBoldMake(15), textColor: UIColorMake(0x07982B))
    private let dateLabel = UILabel(font: UIFontBoldMake(11), textColor: UIColorMake(0x9B9B9B))
    
    override func setSubView() {
        super.setSubView()
        
        
        selectionStyle = .none
        
        backgroundColor = AppStyle.color.background
        
        containerView.addCorner(radius: 10)
        containerView.backgroundColor = UIColorMake(0x2E3036)
        contentView.addSubview(containerView)
        containerView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(AppStyle.margin.left)
            make.top.bottom.equalToSuperview()
        }
        
        containerView.addSubview(typeLabel)
        typeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(12)
            make.top.equalTo(10)
        }

        containerView.addSubview(dateLabel)
        dateLabel.snp.makeConstraints { (make) in
            make.left.equalTo(typeLabel)
            make.bottom.equalTo(-10)
        }
        
        containerView.addSubview(accountLabel)
        accountLabel.snp.makeConstraints { (make) in
            make.right.equalTo(-20)
            make.centerY.equalToSuperview()
        }

    }

}
